/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package raytracer;

import java.awt.Color;

/**
 *
 * @author ferco
 * Trida znazornujici paprsek..hlavni entitu v raytracingu. Paprsek u sebe ponese
 * informace o barve a nejblizsim bodu pruniku
 * ma take metodu na upravu barvy(napriklad pro vypocet osvetleni)
 */
public class Ray {

    //deklarace promennych
    private Vector3D origin;    //pocatek paprsku..U hlavniho paprsku je to
                                //pozice pozorovatele, u odrazeneho je to intersection
    private Vector3D direction; //smer paprsku
    private Intersection intersection;  //bod pruniku s nejmensi vzdalenosti od
                                        //pocatku paprsku
    private Color color;        //barva pixelu na obrazovce

    /**
     *Konstruktor paprsku se zadanym pocatkem a smerem
     *
     *@param origin pocatek paprsku
     *@param direction smer paprsku
     */
    public Ray(Vector3D origin, Vector3D direction){

        this.origin = origin;
        this.direction = direction;
        this.color = Color.black;
    }

    /**
     *Metoda upravi barvu podle parametru scale
     *
     *@param scale mira upraveni barvy
     */
    public void modifyColor(double scale){

        //vypocet jednotlivych slozek barvy
        int r = Math.min(255, (int) (this.color.getRed() + this.color.getRed() * scale));
        int g = Math.min(255, (int) (this.color.getGreen() + this.color.getGreen() * scale));
        int b = Math.min(255, (int) (this.color.getBlue() + this.color.getBlue() * scale));

        //ulozeni vypoctene barvy
        this.color = new Color(r, g, b);
    }

    @Override
    public String toString(){

        return "Ray s pocatkem: " + origin.toString()
               + "smerem: " + direction.toString()
               + "a barvou: " + this.color.toString();
    }

    public Color getColor() {
        return color;
    }

    public Vector3D getDirection() {
        return direction;
    }

    public Intersection getIntersection() {
        return intersection;
    }

    public Vector3D getOrigin() {
        return origin;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public void setIntersection(Intersection intersection) {
        this.intersection = intersection;
    }

    public void setDirection(Vector3D direction) {
        this.direction = direction;
    }

    public void setOrigin(Vector3D origin) {
        this.origin = origin;
    }

    
    
}
